#include "guiterm.hpp"
#ifndef CHARACTERVIEW_HPP
#define CHARACTERVIEW_HPP

class CharacterView
	:public QWidget
{
	Q_OBJECT
public:
	CharacterView(TerminalEmulator *model, CharacterViewConfig *viewConfig, bool abridged=true, QWidget *parent=0);
	void updateTermSize();
	void paintEvent(QPaintEvent *event);
	void finish();
	
	/// Returns whether this view uses abridged mode. If it does, it will
	/// shrink itself if the lower part of the terminal inside it hasn't been
	/// used. On the other hand, if this view is not in abridged mode, it will
	/// resize the terminal inside it to match its height.
	bool isAbridged() const;
	void setAbridged(bool abridged);
	
	QSize sizeHint() const;
	void finalizeSize();
	
protected:
	void resizeEvent(QResizeEvent *event);
	void repaintRegion(int minCol, int maxCol, int minRow, int maxRow);
	
protected slots:
	void rectDirtied(int left, int top, int width, int height);
	void heightChanged();
	/**
	 * Handler for when the cursor moves. If row or col is negative, hides the
	 * cursor; if >= the width or height of the display, the result is
	 * undefined.
	 */
	void cursorMoved(int col, int row);
	
protected:
	TerminalEmulator *model;
	CharacterViewConfig *viewConfig;
	bool programFinished;
	
	bool abridged;
	bool cursorVisible;
	int cursorCol, cursorRow;
	bool sizeFinalized;
};

#endif
